using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Tabs;
using DotNetNuke;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Common.Utilities;

using Common;
public partial class controls_tm_typicalStoreLogoList : System.Web.UI.UserControl
{
    public int myPortalId = Null.NullInteger;

    private void ShowLogoList()
    {
        try
        {
            int tabId = Common.appLibs.GetTabIdByName(Common.consts.constSystemPortalId, "store");
            int moduleId = Common.appLibs.GetModuleIdByName(Common.consts.constSystemPortalId, "store");
            int numItem = Common.systemSettings.sysTypicalStoreMaxRow * Common.systemSettings.sysTypicalStorePerRow;
            string mySQLCmd =
            "SELECT  TOP " + numItem + " a.ownerId,a.storeId,a.storeName,a.logoFile,isnull(a.description,'') AS description" +
            " FROM tm_store a " +
            " WHERE a.grade='" + Common.consts.constTypicalGrade + "' AND " +
            " a.status='" + Common.consts.constStatusENABLE + "'";

            SqlConnection conn = new SqlConnection(Common.sysLibs.GetConnectionString);
            SqlDataAdapter daTmp = new SqlDataAdapter(new SqlCommand(mySQLCmd, conn));
            DataTable dataTbl = new DataTable();
            daTmp.Fill(dataTbl);
            conn.Close();
            ArrayList dataArr = new ArrayList();
            string fileName="";
            for (int idx = 0; idx < dataTbl.Rows.Count; idx++)
            {
                controls_logoList.myImgLinkInfo imgInfo = new controls_logoList.myImgLinkInfo();
                imgInfo.linkUrl = GetStoreURL(dataTbl.Rows[idx]["storeId"].ToString());
                fileName = dataTbl.Rows[idx]["logoFile"].ToString();
                imgInfo.imgPath = sysLibs.GetUpLoadStoreDir + "/" + sysLibs.GetHashString(fileName) + "/" + fileName;
                imgInfo.logoText = Common.sysLibs.SplitToMultiLine(dataTbl.Rows[idx]["storeName"].ToString(),
                                   Common.systemSettings.sysNumberOfWordUnderLogo, Common.systemSettings.sysNumberOfLineUnderLogo);
                imgInfo.description = Common.sysLibs.SplitToMultiLine(dataTbl.Rows[idx]["description"].ToString(), 12, 5);
                imgInfo.openNewPage = true;
                dataArr.Add(imgInfo);
            }
            Tm_LogoList.Display(dataArr, Common.systemSettings.sysTypicalStoreMaxRow,myPortalId);
        }
        catch (Exception exc)
        {
            Exceptions.ProcessModuleLoadException(this, exc);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ShowLogoList();
    }

    private string GetStoreURL(string storeId)
    {
        return "http://"+ Request.Url.Host + "/" + Request.ApplicationPath + "/" + storeId;  
    }
}
